package com.hxf.web.action;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import net.sf.json.JSONObject;
import net.sf.json.util.JSONUtils;

import com.hxf.common.Definition;
import com.hxf.common.GlobalConstant;
import com.hxf.common.GlobalURL;
import com.hxf.common.JsonUtilVo;
import com.hxf.common.JsonUtils;
import com.hxf.common.PublicUtil;
import com.hxf.dto.AppraisalDto;
import com.hxf.dto.MealMenuDto;
import com.hxf.dto.MealOrderDetailDto;
import com.hxf.dto.MealOrderDto;
import com.hxf.dto.MealPreferentialDto;
import com.hxf.dto.RestaurantDto;
import com.hxf.dto.ReturnData; 
import com.hxf.dto.UserDto;
import com.hxf.dto.VersionDto;
import com.hxf.exception.ServiceException;
import com.hxf.web.vo.AppraisalVo;
import com.hxf.web.vo.BaseVo;
import com.hxf.web.vo.MealMenuVo;
import com.hxf.web.vo.PreferentialVo;
import com.hxf.web.vo.RestaurantVo;
import com.hxf.web.vo.VersionVo;

public class ApiAction extends WebActionBase {
	/**
	 * 九宫格
	 * @return
	 */
	public String main() {
		return "main-page";
	}
	
	/**
	 * 登录和注册页面
	 * @return
	 */ 
	public String appLoginRegistPage() {
		return "app-login-regist-page";
	}
	
	/**
	 * 登录
	 * @return
	 */
	public String m_LoginIn() {
		UserDto ud = new UserDto();
		try {
			System.out.println(getRequest().getQueryString());
			String username = getParameter("username");
			String pwd = getParameter("pwd");
			//用户名
			if (!PublicUtil.isNotNullAndEmpty(username)) { 
				msg = "用户名不能为空！";
				return "error";
			}
			//密码
			if (!PublicUtil.isNotNullAndEmpty(pwd)) { 
				msg = "密码不能为空！";
				return "error";
			}
			ud.setUserName(username);
			ud.setUserPwd(pwd);
			ud.setUserType(2);
			int result = super.serviceFacade.getUserService().loginUser(ud);
			System.out.println("result:" + result);
			//成功
			if (result == 0) { 
				return m_PSOffersSearch();
			}
			//用户名错误
			if (result == -1) { 
				msg = "用户名不存在！";
				return "error";
			}
			//密码错误
			if (result == -2) { 
				msg = "密码错误！";
				return "error";
			}
			
		} catch (ServiceException e) { 
			logger.debug(e.getMessage(), e);
		}
		return m_PSOffersSearch();
	}
	
	/**
	 * 登出
	 * @return
	 */
	public String m_LoginOut() {
		String username = getParameter("username");
		BaseVo bv = null;
		try {
			//用户名
			if (!PublicUtil.isNotNullAndEmpty(username)) {
				bv = new BaseVo(Definition.PARAMER_ERROR, Definition.PARAMER_DESCRIPTION + " username error"); 
				println(JsonUtils.beanToJson(bv));
				return null;
			}
			bv = new BaseVo(Definition.SUCCESS_CODE, Definition.SUCCESS_DESCRIPTION); 
			getSession().setAttribute("userDto"+username, null);
			getSession().removeAttribute("userDto");
			println(JsonUtils.beanToJson(bv));
		}catch(IOException e) {
			logger.debug(e.getMessage(), e);
		}
		
		return null;
	}
	 
	/**
	 * 注册
	 * @return
	 */
	public String m_Registe() {   
		try {
			UserDto ud = new UserDto(); 
			String username = getParameter("username");
			String pwd = getParameter("pwd");
			String confirmPwd = getParameter("confirm_pwd");
			String phoneNo = getParameter("phone_no");
			
			if (!PublicUtil.isNotNullAndEmpty(username)) { 
				msg = "用户名不能为空！";
				return "error";
			}
			boolean bool = super.serviceFacade.getUserService().validateUserName(getParameter("username"));
			if (!bool) {
				msg = "用户名已注册！";
				return "error";
			}
			
			if (!PublicUtil.isNotNullAndEmpty(pwd)) { 
				msg = "密码不能为空！";
				return "error";
			}
			
			if (!PublicUtil.isNotNullAndEmpty(confirmPwd)) { 
				msg = "确认密码不能为空！";
				return "error";
			}
			
			if (!confirmPwd.equals(pwd)) {
				msg = "确认密码输入错误！";
				return "error";
			}
			
			if (!PublicUtil.isNotNullAndEmpty(phoneNo)) {
				msg = "手机号不能为空！";
				return "error";
			}
			
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			ud.setUserName(username);
			ud.setUserPwd(pwd);
			ud.setUserPhone(phoneNo); 
			ud.setStatus(1);
			ud.setUserType(2);
			ud.setCreateTime(sdf.format(new Date()));
			super.serviceFacade.getUserService().save(ud);
			return m_PSOffersSearch();
		} catch (ServiceException e) {
			logger.debug(e.getMessage(), e);
			msg = "注册失败！";
			return "error";
		}
		  
	}  
	
	/**
	 * 验证用户名
	 * @return
	 */
	public String m_CheckUser() {
		try {
			BaseVo bv = null;
			try {
				String username = getParameter("username"); 
				if (!PublicUtil.isNotNullAndEmpty(username)) {
					bv = new BaseVo(Definition.PARAMER_ERROR, Definition.PARAMER_DESCRIPTION + " username error"); 
					println(JsonUtils.beanToJson(bv));
					return null;
				}
				UserDto ud = new UserDto();
				ud.setUserName(username);
				boolean bool = super.serviceFacade.getUserService().validateUserName(getParameter("username"));
				if (!bool) {
					bv = new BaseVo(Definition.REG_USERNAME_ERROR, Definition.REG_USERNAME_DESCRIPTION + " username exists"); 
					println(JsonUtils.beanToJson(bv));
					return null;
				}
				bv = new BaseVo(Definition.SUCCESS_CODE, Definition.SUCCESS_DESCRIPTION); 
				println(JsonUtils.beanToJson(bv)); 
			} catch (ServiceException e) {
				bv = new BaseVo(Definition.NUKNOW_ERROR, Definition.NUKNOW_DESCRIPTION + " " + e.getMessage()); 
				println(JsonUtils.beanToJson(bv)); 
				logger.debug(e.getMessage(), e);
			}
		} catch (IOException e) {
		   logger.debug(e.getMessage(), e);
		}
		return null;
	}
	
	/**
	 * 个人中心主页面
	 * @return
	 */
	public String m_Personal() {  
		try {
			String userId = getParameter("id");
			if (!PublicUtil.isNotNullAndEmpty(userId)) { 
				msg = "请先登录！";
				return "error";
			}
			UserDto ud = (UserDto)super.serviceFacade.getUserService().get(UserDto.class, 1);
			getRequest().setAttribute("userDto", ud);
		} catch (ServiceException e) { 
			logger.debug(e.getMessage(), e);
			msg = "程序出错！";
			return "error";
		}
		return "user-center";
	}
	
	/**
	 * 跳转到修改用户信息页面
	 * @return
	 */
	public String m_userUpdate() {
		try {
			try {
				/*String userId = getParameter("userId");
				if (!PublicUtil.isNotNullAndEmpty(userId)) {
					println(Definition.PARAMER_ERROR);
					return null;
				}*/
				UserDto ud = (UserDto)super.serviceFacade.getUserService().get(UserDto.class, 5);
				getRequest().setAttribute("userDto", ud);
			} catch (ServiceException e) {
				println(Definition.NUKNOW_ERROR);
				logger.debug(e.getMessage(), e);
			}
		} catch (IOException e) {
			logger.debug(e.getMessage(), e);
		} 
		return "user-update";
	}
	
	/**
	 * 保存修改个人信息
	 * @return
	 */
	public String m_PersonalModify() { 
			String userId = getParameter("userId");
			String userName = getParameter("userName");
			String realName = getParameter("realName");  
			String userPhone = getParameter("userPhone");
			String userSex = getParameter("userSex");
			String userEmail = getParameter("userEmail"); 
			String userZipCode = getParameter("userZipCode"); 
			String qq = getParameter("qq"); 
			String userAddress = getParameter("userAddress"); 
			/*BaseVo bv= null;
			if (PublicUtil.isNotNullAndEmpty(userId)) { 
				bv = new BaseVo(Definition.PARAMER_ERROR, Definition.PARAMER_DESCRIPTION + " userId error"); 
				println(JsonUtils.beanToJson(bv)); 
				return null;
			}
			
			if (!PublicUtil.isNotNullAndEmpty(userName)) {
				bv = new BaseVo(Definition.PARAMER_ERROR, Definition.PARAMER_DESCRIPTION + " username error"); 
				println(JsonUtils.beanToJson(bv));
				return null;
			}  */
			
			try {
				System.out.println("=========------===" + userSex + "---" + userId + "---" + userEmail);
				UserDto ud = (UserDto)super.serviceFacade.getUserService().get(UserDto.class, 5);
				ud.setQq(qq);
				ud.setUserPhone(userPhone);
				ud.setUserEmail(userEmail);
				ud.setRealName(realName);
			//	ud.setUserSex(userSex);
				ud.setUserZipCode(userZipCode);
				ud.setUserAddress(userAddress);
				super.serviceFacade.getUserService().update(ud);
				msg = "成功";
				return "error";
			} catch (ServiceException e) {
				//bv = new BaseVo(Definition.NUKNOW_ERROR, Definition.NUKNOW_DESCRIPTION + " " + e.getMessage());
				//println(JsonUtils.beanToJson(bv));
				logger.debug(e.getMessage(), e);
			}
	//	} catch (IOException e) {
	//		logger.debug(e.getMessage(), e);
	//	}
		return null;
	}
	
	/**
	 * 修改密码页面
	 * @return
	 */
	public String m_passwordUpdate() {
		UserDto ud = null;
		try {
			ud = (UserDto)super.serviceFacade.getUserService().get(UserDto.class, 5);
			getRequest().setAttribute("userDto", ud);
		} catch (ServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return "pwd-update";
	}
	/**
	 * 修改密码接口
	 * @return
	 */
	public String m_PwdModify() {
		String userId = getParameter("userId");
		String pwd = getParameter("pwd");
		String new_pwd = getParameter("new_pwd");
		String confirm_pwd = getParameter("confirm_pwd");
		try {
			BaseVo bv = null;
			if (PublicUtil.isNotNullAndEmpty(userId)) {  
				msg = "用户id不能为空";
				return "error";
			} 
			
			if (!PublicUtil.isNotNullAndEmpty(pwd)) { 
				msg = "旧密码不能为空";
				return "error";
			} 
			
			if (!PublicUtil.isNotNullAndEmpty(new_pwd)) { 
				msg = "新密码不能为空";
				return "error";
			} 
			
			if (!PublicUtil.isNotNullAndEmpty(confirm_pwd)) { 
				msg = "确认密码不能为空";
				return "error";
			}
			//新密码和确认密码匹配
			if (!new_pwd.equals(confirm_pwd)) { 
				msg = "确认密码错误";
				return "error";
			}
			try {
				UserDto ud = (UserDto)super.serviceFacade.getUserService().get(UserDto.class, 5);
				 
				//密码匹配
				if (!pwd.equals(ud.getUserPwd())) { 
					msg = "旧密码不匹配";
					return "error";
				}
				ud.setUserPwd(new_pwd);
				super.serviceFacade.getUserService().update(ud);
				msg = "成功";
				return "error";
			} catch (ServiceException e) {
				bv = new BaseVo(Definition.NUKNOW_ERROR, Definition.NUKNOW_DESCRIPTION + " " + e.getMessage()); 
				println(JsonUtils.beanToJson(bv));
				logger.debug(e.getMessage(), e);
			}
		} catch (IOException e) {
			logger.debug(e.getMessage(), e);
		} 
		return null;
	}
	
	/**
	 * 查询版本信息(启动加载接口)
	 * @return
	 */
	public String m_login_in() {
		VersionVo vo = null;
		try {
			try {
				VersionDto vd = super.serviceFacade.getVersionService().findVersionDto();
				if (vd != null) {
					vo = new VersionVo(vd.getVersionNo(), vd.getRemark(), Definition.SUCCESS_CODE, Definition.SUCCESS_DESCRIPTION);;
				} else {
					vo = new VersionVo("0", "", Definition.NUKNOW_ERROR, "查询失败"+Definition.NUKNOW_DESCRIPTION);;
				}
				println(JsonUtils.beanToJson(vo)); 
			} catch (ServiceException e) {
				 vo = new VersionVo("0", "", Definition.NUKNOW_ERROR, Definition.NUKNOW_DESCRIPTION +"异常错误" + e.getMessage());;
				 logger.debug(e.getMessage(), e); 
				 println(JsonUtils.beanToJson(vo)); 
			}
		} catch (IOException e) {
			logger.debug(e.getCause(), e);
		}
		return null;
	} 
	
	
	
	/**
	 * 转介绍（把会员介绍给其他餐厅)
	 * @return
	 */
	public String m_Referrals() {
		return null;
	}
	
	/**
	 * 点餐餐厅列表
	 * @return
	 */
	public String m_Restaurant() { 
		String province = getParameter("province");
		String city = getParameter("city"); 
		String town = getParameter("town"); 
		String road = getParameter("road");     
		String name = getParameter("name");
		
		RestaurantDto rd = new RestaurantDto();
		rd.setProvince(province);
		rd.setCity(city);
		rd.setDistrict(town);
		rd.setStreet(road);
		rd.setName(name);
	 	try {
			ReturnData<RestaurantDto> result = super.serviceFacade.getRestaurantService().findByRestaurantSelectName(rd, targetPage, pageSize);
			List<RestaurantDto> list = result.getResultlist();
			List<RestaurantVo> voList = new ArrayList<RestaurantVo>();
			
			if (null != list && list.size() > 0) {
				RestaurantVo vo = null;
				RestaurantDto dto = null;
				for (int i = 0;i < list.size(); i++) {
					dto = list.get(i);
					vo = new RestaurantVo();
					vo.setId(dto.getId());
					vo.setName(dto.getName());
					vo.setBeginTime(dto.getBeginTime());
					vo.setEndTime(dto.getEndTime());
					if (PublicUtil.isNotNullAndEmpty(dto.getImages1())) {
						vo.setImageUrl(getWebUrl()+dto.getImages1());
					} else {
						vo.setImageUrl("");
					}
					vo.setLinkman(dto.getLinkman());
					vo.setMealStyle("湘菜馆");
					/*if (PublicUtil.isNotNullAndEmpty(dto.getMealStyle())) {
						String [] mealStyle = dto.getMealStyle().split(",");
						String styleName = "";
						if (mealStyle != null) {
							for (int j = 0;j < mealStyle.length; j++) {
								if (Integer.parseInt(mealStyle[j]) == 0) {
									styleName = "";
								}
								
								if (Integer.parseInt(mealStyle[j]) == 1) {
									styleName += "";								
								}
								
								if (Integer.parseInt(mealStyle[j]) == 2) {
									styleName += "";
								}
								
								if (Integer.parseInt(mealStyle[j]) == 3) {
									styleName += "";
								}
							}
						}
					}*/
					//vo.setMealStyle(dto.getMealStyle());
					vo.setFixed(dto.getMoilbe());
					vo.setAddress(dto.getAddress()); 
					//点击图片地址
					vo.setImgDetailUrl(getLpUrl()+GlobalURL.RESTAURANT_INFO_URL);
					voList.add(vo);
				}
			}
			json = replaceJson(JsonUtils.listToJson(voList));
			System.out.println(json);
	 	} catch (ServiceException e) {
			logger.debug(e.getMessage(), e);
		}
	 	
		return "restaurant-list";
	}
	
	/**
	 * 餐厅点餐页面(餐厅菜肴列表页面)
	 * @return
	 */
	public String m_RestaurantMealMenu() {
		String id = getParameter("id"); 
		try {
			if (!PublicUtil.isNotNullAndEmpty(id)) {  
				msg = "餐厅ID不能为空";
				return "error";
			} 
			MealMenuDto mmDto = new MealMenuDto();
			mmDto.setId(Integer.parseInt(id)); 
			try {
				ReturnData<MealMenuDto> result = super.serviceFacade.getMealMenuService().findByMealMenu(mmDto, targetPage, pageSize);
				json = replaceJson(JsonUtils.listToJson(result.getResultlist()));
				List<MealMenuDto> list = result.getResultlist();
				List<MealMenuVo> voList = new ArrayList<MealMenuVo>();
				
				if (null != list && list.size() > 0) {
					MealMenuVo vo = null;
					MealMenuDto dto = null;
					for (int i = 0;i < list.size(); i++) {
						dto = list.get(i);
						vo = new MealMenuVo();
						vo.setId(dto.getId());
						vo.setImageUrl(getWebUrl()+dto.getImages());
						vo.setIntroduce(dto.getIntroduce());
						if (dto.getRecommend()) {
							vo.setIsRecommend(1);
						} else {
							vo.setIsRecommend(0);
						}
						if (dto.getIsSell()) {
							vo.setIsSell(1);
						} else {
							vo.setIsSell(0);
						}
						
						vo.setMealMenuId(String.valueOf(dto.getMealMenuId()));
						vo.setMenuName(dto.getMenuName());
						vo.setOrderBy(dto.getOrderBy());
						vo.setPrice(dto.getPrice()); 
						if (dto.getTaste() == MealMenuDto.TASTE_0) {
							vo.setTaste("不辣");
						}
						if (dto.getTaste() == MealMenuDto.TASTE_1) {
							vo.setTaste("香辣");
						}
						if (dto.getTaste() == MealMenuDto.TASTE_2) {
							vo.setTaste("香辣(可选)");
						}
						if (dto.getTaste() == MealMenuDto.TASTE_3) {
							vo.setTaste("微辣");
						} 
						vo.setStyleName(String.valueOf(dto.getMenuTypeId()));
						voList.add(vo);
					}
				}
				json = replaceJson(JsonUtils.listToJson(voList));
				System.out.println(json);
			} catch (ServiceException e) {
				logger.debug(e.getMessage(), e);
				println(Definition.NUKNOW_DESCRIPTION + e.getMessage());
			}
		} catch (IOException e) {
			logger.debug(e.getMessage(), e);
		}
		 
		return "meal-menu-list";
	}
	
	/**
	 * 餐厅点餐页面(餐厅菜肴列表页面)
	 * @return
	 */
	public String m_RestaurantMealMenuTargetPage() {
		String id = getParameter("id"); 
		try {
			if (!PublicUtil.isNotNullAndEmpty(id)) {  
				msg = "餐厅ID不能为空";
				return "error";
			} 
			MealMenuDto mmDto = new MealMenuDto();
			mmDto.setId(Integer.parseInt(id)); 
			try {
				ReturnData<MealMenuDto> result = super.serviceFacade.getMealMenuService().findByMealMenu(mmDto, targetPage, pageSize);
				json = replaceJson(JsonUtils.listToJson(result.getResultlist()));
				
			} catch (ServiceException e) {
				logger.debug(e.getMessage(), e);
				println(Definition.NUKNOW_DESCRIPTION + e.getMessage());
			}
		} catch (IOException e) {
			logger.debug(e.getMessage(), e);
		}
		 
		return "json";
	}
	
	/**
	 * 餐厅详细信息页面
	 */
	public String m_RestaurantInfo() {
		String id = getParameter("id");  
		if (!PublicUtil.isNotNullAndEmpty(id)) {  
			msg = "餐厅id不能为空";
			return "error";
		}  
		try {
			RestaurantDto rDto = (RestaurantDto)super.serviceFacade.getRestaurantService().get(RestaurantDto.class, Integer.parseInt(id));
			AppraisalDto apDto = new AppraisalDto();
			apDto.setAppraisalType(AppraisalDto.APPRAISAL_TYPE_2);
			apDto.setAppraisalTypeId(rDto.getId());
			ReturnData<AppraisalDto> result = super.serviceFacade.getAppraisalService().findAppraisal(apDto, 1, 5);
			List<AppraisalDto> appraisalDtoList = result.getResultlist();
			setRecordCount(result.getRecordcount());
			getRequest().setAttribute("appraisalDtoList", appraisalDtoList);
			getRequest().setAttribute("restaurantDto", rDto);
		} catch (ServiceException e) {
			logger.debug(e.getMessage(), e); 
		}
		 
		 
		return "restaurant-info";
	}
	
	/**
	 * 餐厅搜索结果页面接口
	 * @return
	 */
	public String m_RestaurantTargetPage() {
		String province = getParameter("province");
		String city = getParameter("city"); 
		String town = getParameter("town"); 
		String road = getParameter("road");     
		String name = getParameter("name");
		
		RestaurantDto rd = new RestaurantDto();
		rd.setProvince(province);
		rd.setCity(city);
		rd.setDistrict(town);
		rd.setStreet(road);
		rd.setName(name);
	 	try {
			ReturnData<RestaurantDto> result = super.serviceFacade.getRestaurantService().findByRestaurantSelectName(rd, targetPage, pageSize);
			List<RestaurantDto> list = result.getResultlist();
			List<RestaurantVo> voList = new ArrayList<RestaurantVo>();
			
			if (null != list && list.size() > 0) {
				RestaurantVo vo = null;
				RestaurantDto dto = null;
				for (int i = 0;i < list.size(); i++) {
					dto = list.get(i);
					vo = new RestaurantVo();
					vo.setId(dto.getId());
					vo.setName(dto.getName());
					vo.setBeginTime(dto.getBeginTime());
					vo.setEndTime(dto.getEndTime());
					vo.setImageUrl(getWebUrl()+dto.getImages1());
					vo.setLinkman(dto.getLinkman());
					vo.setMealStyle(dto.getMealStyle());
					vo.setFixed(dto.getMoilbe());
					vo.setAddress(dto.getAddress()); 
					voList.add(vo);
				}
			}
			json = replaceJson(JsonUtils.listToJson(voList));
			System.out.println(json);
	 	} catch (ServiceException e) {
			logger.debug(e.getMessage(), e);
		}
	 	
		return "json";
	}
	
	/**
	 * 我的订单
	 * @return
	 */
	public String m_MyOrders() {
		String userId = getParameter("userId"); 
		String username = getParameter("username"); 
		try {
			try {
				if (PublicUtil.isNotNullAndEmpty(userId)) {  
					println(Definition.PARAMER_DESCRIPTION + "userId error");
					return null;
				}
				//未登录 返回登录页面
				Object obj = getSession().getAttribute("userDto"+username);
				if (obj == null) {
					println(Definition.USERNAME_DESCRIPTION + "username not login");
					return null;
				}
				MealOrderDto moDto = new MealOrderDto();
				moDto.setUserId(Integer.parseInt(userId));
				ReturnData<MealOrderDto> result = super.serviceFacade.getOrderService().findMealOrder(moDto, targetPage, pageSize);
			} catch (ServiceException e) {
				logger.debug(e.getMessage(), e);
			}
		} catch (IOException e) {
			logger.debug(e.getMessage(), e);
		}
		return null;
	}
	
	/**
	 * 订单详细列表
	 * @return
	 */
	public String m_DetailOrdersList() {
		String userId = getParameter("userId");
		String ordersId = getParameter("ordersId");
		String username = getParameter("username");
		
		try {
			try {
				if (PublicUtil.isNotNullAndEmpty(userId)) {  
					println(Definition.PARAMER_DESCRIPTION + "userId error");
					return null;
				}
				
				if (PublicUtil.isNotNullAndEmpty(username)) {  
					println(Definition.PARAMER_DESCRIPTION + "username error");
					return null;
				}
				//未登录 返回登录页面
				Object obj = getSession().getAttribute("userDto"+username);
				if (obj == null) {
					println(Definition.USERNAME_DESCRIPTION + "username not login");
					return null;
				}
				MealOrderDto moDto = new MealOrderDto();
				moDto.setUserId(Integer.parseInt(userId));
				moDto.setOrderId(ordersId);
				//订单
				MealOrderDto orderDto = (MealOrderDto)super.serviceFacade.getOrderService().get(MealOrderDto.class, ordersId);
				//订单详细
				MealOrderDetailDto modDto = new MealOrderDetailDto();
				modDto.setOrderId(ordersId); 
				ReturnData<MealOrderDetailDto> result = super.serviceFacade.getOrderService().findMealOrderDetail(modDto, targetPage, pageSize);
			} catch (ServiceException e) {
				logger.debug(e.getMessage(), e);
			}
		} catch (IOException e) {
			logger.debug(e.getMessage(), e);
		}
		return null;
	}
	
	/**
	 * 菜品详细信息接口
	 * @return
	 */
	public String m_DishInfo() {
		String dishId = getParameter("id"); 
		if (!PublicUtil.isNotNullAndEmpty(dishId)) {  
			msg = "菜肴ID不能为空";
			return "error";
		}  
		
		try {
			MealMenuDto mmDto = (MealMenuDto)super.serviceFacade.getMealMenuService().get(MealMenuDto.class, Integer.parseInt(dishId));
			AppraisalDto apDto = new AppraisalDto();
			apDto.setAppraisalType(AppraisalDto.APPRAISAL_TYPE_1);
			apDto.setAppraisalTypeId(mmDto.getId());
			ReturnData<AppraisalDto> result = super.serviceFacade.getAppraisalService().findAppraisal(apDto, 1, 5);
			List<AppraisalDto> appraisalDtoList = result.getResultlist();
			setRecordCount(result.getRecordcount());
			
			getRequest().setAttribute("appraisalDtoList", appraisalDtoList);
			getRequest().setAttribute("mealMenuDto", mmDto);
		} catch (ServiceException e) {
			logger.debug(e.getMessage(), e);
		}
		 
		return "meal-menu-info";
	}

	/**
	 * 菜品搜索信息页面接口
	 * @return
	 */
	public String m_DishSearch() {
		String province = getParameter("province");
		String city = getParameter("city"); 
		String town = getParameter("town"); 
		String road = getParameter("road");     
		String name = getParameter("dishName");
		
		RestaurantDto rd = new RestaurantDto();
		rd.setProvince(province);
		rd.setCity(city);
		rd.setDistrict(town);
		rd.setStreet(road); 
		
		MealMenuDto mmDto = new MealMenuDto();
		mmDto.setMenuName(name);
	 	try {  
	 		ReturnData<MealMenuVo> result = super.serviceFacade.getMealMenuService().findMealMenuByRestaurant(rd, mmDto, targetPage, pageSize);
	 		json = replaceJson(JsonUtils.listToJson(result.getResultlist()));
	 		System.out.println(json);
	 	} catch (ServiceException e) {
			logger.debug(e.getMessage(), e);
		}
		return "meal-menu-list";
	}
	
	/**
	 * 菜品搜索信息页面接口
	 * @return
	 */
	public String m_DishSearchByTargetPage() {
		String province = getParameter("province");
		String city = getParameter("city"); 
		String town = getParameter("town"); 
		String road = getParameter("road");     
		String name = getParameter("dishName");
		
		RestaurantDto rd = new RestaurantDto();
		rd.setProvince(province);
		rd.setCity(city);
		rd.setDistrict(town);
		rd.setStreet(road); 
		
		MealMenuDto mmDto = new MealMenuDto();
		mmDto.setMenuName(name);
	 	try { 
	 		ReturnData<MealMenuVo> result = super.serviceFacade.getMealMenuService().findMealMenuByRestaurant(rd, mmDto, targetPage, pageSize);
	 		json = replaceJson(JsonUtils.listToJson(result.getResultlist()));
	 		System.out.println(json);
	 	} catch (ServiceException e) {
			logger.debug(e.getMessage(), e);
		}
		return "json";
	}
	
	/**
	 * 优惠信息主页面接口
	 * @return
	 */
	public String m_SpecialOffers() {
		
		return null;
	}
	
	/**
	 * 优惠详细信息接口
	 * @return
	 */
	public String m_SODetailsInfo() {
		try {
			String specialOfferId = getParameter("id");
			System.out.println(specialOfferId + "---------------");
			if (!PublicUtil.isNotNullAndEmpty(specialOfferId)) {  
				//println(Definition.PARAMER_DESCRIPTION + " specialOfferId error");
				msg = "优惠ID不能为空！";
				return "error";
			}   
			try {
				MealPreferentialDto mpDto = (MealPreferentialDto)super.serviceFacade.getPreferentialService().get(MealPreferentialDto.class, Integer.parseInt(specialOfferId));
				if (null != mpDto) {
					List<MealMenuDto> menuList = new ArrayList<MealMenuDto>();
					if (null != mpDto.getMealMenuId() && !"".equals(mpDto.getMealMenuId())) {
						menuList = super.serviceFacade.getMealMenuService().findByMealMenuByIds(mpDto.getMealMenuId());
					}
					RestaurantDto restaurantDto = (RestaurantDto)super.serviceFacade.getRestaurantService().get(RestaurantDto.class, mpDto.getId());
				 
					AppraisalDto apDto = new AppraisalDto();
					apDto.setAppraisalType(AppraisalDto.APPRAISAL_TYPE_0);
					apDto.setAppraisalTypeId(mpDto.getId());
					ReturnData<AppraisalDto> result = super.serviceFacade.getAppraisalService().findAppraisal(apDto, 1, 5);
					List<AppraisalDto> appraisalDtoList = result.getResultlist();
					setRecordCount(result.getRecordcount());
					getRequest().setAttribute("appraisalDtoList", appraisalDtoList);
					getRequest().setAttribute("mealMenuList", menuList);
					getRequest().setAttribute("restaurantDto", restaurantDto);
				} else {
					msg = "优惠不存在";
					return "error";
				}
				getRequest().setAttribute("preferentialDto", mpDto);
			} catch (ServiceException e) {
				println(Definition.NUKNOW_DESCRIPTION + " " + e.getMessage());
				logger.debug(e.getMessage(), e);
			}
		} catch (IOException e) {
			logger.debug(e.getMessage(), e);
		}
		return "perferential-info";
	}
	
	/**
	 * 搜索优惠信息结果页面接口(显示报文)
	 * @return
	 */
	public String m_PSOffersSearch() {
		String province = getParameter("province");
		String city = getParameter("city"); 
		String town = getParameter("town"); 
		String road = getParameter("road");     
		String name = getParameter("dishName");
		
		RestaurantDto rd = new RestaurantDto();
		rd.setProvince(province);
		rd.setCity(city);
		rd.setDistrict(town);
		rd.setStreet(road); 
		
		MealPreferentialDto mpDto = new MealPreferentialDto();
		mpDto.setName(name);
	 	try { 
	 		ReturnData<PreferentialVo> result = super.serviceFacade.getPreferentialService().findMealPreferentialByRestaurant(rd, mpDto, targetPage, pageSize);
	 		json = replaceJson(JsonUtils.listToJson(result.getResultlist()));
	 		System.out.println(json + "----");
	 	} catch (ServiceException e) {
			logger.debug(e.getMessage(), e);
		}
		return "perferential-list";
	}
	
	/**
	 * 搜索优惠信息结果页面接口(只返回JSON)
	 * @return
	 */
	public String m_PSOffersSearchByTargetPage() {
		String province = getParameter("province");
		String city = getParameter("city"); 
		String town = getParameter("town"); 
		String road = getParameter("road");     
		String name = getParameter("dishName");
		String orderBy = getParameter("order_by");
		
		RestaurantDto rd = new RestaurantDto();
		rd.setProvince(province);
		rd.setCity(city);
		rd.setDistrict(town);
		rd.setStreet(road);  
		System.out.println(orderBy + "------------------");  
		//排序 默认 0 价格(低到高) 1  价格(高到低) 2
		if (PublicUtil.isNotNullAndEmpty(orderBy)) {
			//默认不排序
			if ("0".equals(orderBy.trim())) {
				orderBy = " order by preferential_price";
			}
			if ("1".equals(orderBy.trim())) {
				orderBy = " order by preferential_price";
			}
			if ("2".equals(orderBy.trim())) {
				orderBy = " order by preferential_price desc";
			}
		}
		 
		MealPreferentialDto mpDto = new MealPreferentialDto();
		mpDto.setName(name);
		//作排序
		mpDto.setPackageRemark(orderBy);
	 	try { 
	 		ReturnData<PreferentialVo> result = super.serviceFacade.getPreferentialService().findMealPreferentialByRestaurant(rd, mpDto, targetPage, pageSize);

	 		json = replaceJson(JsonUtils.listToJson(result.getResultlist()));
	 		System.out.println(json);
	 		return "json";
	 	} catch (ServiceException e) {
			logger.debug(e.getMessage(), e);
		}
		return null;
	}
	
	/**
	 * 优惠 立即购买
	 * @return
	 */
	public String m_preferentialBuyNow() {
		String id  = getParameter("id");
		if (!PublicUtil.isNotNullAndEmpty(id)) { 
			msg = "优惠ID不能为空！";
			return "error";
		}  
		try {
			MealPreferentialDto preferentialDto = (MealPreferentialDto)super.serviceFacade.getPreferentialService().get(MealPreferentialDto.class, Integer.parseInt(id));
			getRequest().setAttribute("preferentialDto", preferentialDto);
		} catch (NumberFormatException e) {
			 logger.debug(e.getMessage(), e);
		} catch (ServiceException e) {
			logger.debug(e.getMessage(), e);
		}
		
		return "perferential-buy";
	}
	/**
	 * 我的优惠
	 * @return
	 */
	public String m_MySpecialOffers() {
		return null;
	}
	
	/**
	 * 评价列表
	 * @return
	 */
	public String m_appraisal() {
		String id = getParameter("id");
		String type = getParameter("type");
		if (!PublicUtil.isNotNullAndEmpty(id)) {
			msg = "id不能为空";
			return "error";
		}
		if (!PublicUtil.isNotNullAndEmpty(type)) {
			msg = "优惠类型不能为空";
			return "error";
		}
		int appraisalType = Integer.parseInt(type);
		try {
			String name = "";
			if (AppraisalDto.APPRAISAL_TYPE_0 == appraisalType) {
				MealPreferentialDto mpDto = (MealPreferentialDto)super.serviceFacade.getPreferentialService().get(MealPreferentialDto.class, Integer.parseInt(id));
				if (null != mpDto) {
					name = mpDto.getName();
				}
			}
			if (AppraisalDto.APPRAISAL_TYPE_1 == appraisalType) {
				MealMenuDto mmDto = (MealMenuDto) super.serviceFacade.getMealMenuService().get(MealMenuDto.class, Integer.parseInt(id));
				if (null != mmDto) {
					name = mmDto.getMenuName();
				}
			}
			if (AppraisalDto.APPRAISAL_TYPE_2 == appraisalType) {
				RestaurantDto rDto = (RestaurantDto) super.serviceFacade.getRestaurantService().get(RestaurantDto.class, Integer.parseInt(id));
				if (null != rDto) {
					name = rDto.getName();
				}
			}
			getRequest().setAttribute("name", name);
			AppraisalDto apDto = new AppraisalDto();
			apDto.setAppraisalType(AppraisalDto.APPRAISAL_TYPE_1);
			apDto.setAppraisalTypeId(Integer.parseInt(id));
			apDto.setAppraisalType(Integer.parseInt(type));
			ReturnData<AppraisalDto> result  = super.serviceFacade.getAppraisalService().findAppraisal(apDto, 1, 5);
			List<AppraisalDto> appraisalDtoList = result.getResultlist(); 
			List<AppraisalVo> appraisalVolist = new ArrayList<AppraisalVo>(); 
			if (null != appraisalDtoList) {
				
				AppraisalVo appraisalVo = null;
				AppraisalDto appraisalDto = null;
				for (int i = 0;i < appraisalDtoList.size(); i++) {
					appraisalDto = appraisalDtoList.get(i); 
					appraisalVo = new AppraisalVo();
					appraisalVo.setAppraisalInfo(appraisalDto.getAppraisalInfo());
					appraisalVo.setCreateDate(appraisalDto.getCreateDate());
					appraisalVo.setCredit(appraisalDto.getCredit());
					appraisalVo.setId(appraisalDto.getId());
					appraisalVo.setUserLevel(appraisalDto.getUserLevel());
					appraisalVo.setAppUserName(appraisalDto.getAppUserName());
					
					appraisalVolist.add(appraisalVo);
				}
			}
			json = replaceJson(JsonUtils.listToJson(appraisalVolist));
			System.out.println(json + "====" + name);
		} catch (ServiceException e) {
			logger.debug(e.getMessage(), e);
		}
		
		return "appraisal-list";
	}
	
	/**
	 * 评价分页
	 * @return
	 */
	public String m_appraisalTargetPage() {
		String id = getParameter("id");
		String type = getParameter("type");
		if (!PublicUtil.isNotNullAndEmpty(id)) {
			msg = "id不能为空";
			return "error";
		}
		if (!PublicUtil.isNotNullAndEmpty(type)) {
			msg = "优惠类型不能为空";
			return "error";
		}
		
		try {
			AppraisalDto apDto = new AppraisalDto();
			apDto.setAppraisalType(AppraisalDto.APPRAISAL_TYPE_1);
			apDto.setAppraisalTypeId(Integer.parseInt(id));
			apDto.setAppraisalType(Integer.parseInt(type));
			ReturnData<AppraisalDto> result  = super.serviceFacade.getAppraisalService().findAppraisal(apDto, 1, 5);
			List<AppraisalDto> appraisalDtoList = result.getResultlist();
			json = replaceJson(JsonUtils.listToJson(appraisalDtoList));
		} catch (ServiceException e) {
			logger.debug(e.getMessage(), e);
		}
		
		return "json";
	}
	
	
	/**
	 * 我的绿卡主页面接口
	 * @return
	 */
	public String m_MyCards() {
		return null;
	}
	
	/**
	 * 绿卡详细信息页面接口
	 * @return
	 */
	public String m_DetilCardInfo() {
		return null;
	}
	
	/**
	 * 绿卡搜索页面接口
	 * @return
	 */
	public String m_SOffersSearch() {
		return null;
	}
	
	/**
	 * 更多绿卡页面接口
	 * @return
	 */
	public String m_SOffersMore() {
		return null;
	}
	
	/**
	 * 帮助
	 * @return
	 */
	public String m_Help() {
		return null;
	}
	
	private static String replaceJson(String str) {
		return str.replace("\"", "'").replace("\\", "");
	}
}
